package com.pai4j.pay.config;

import com.pai4j.common.config.interceptor.ValidateLoginInterceptor;
import com.pai4j.pay.config.interceptor.GetAppIdInterceptor;
import com.pai4j.pay.config.interceptor.ValidateAccessPaymentPermissionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebChatPaymentMvnConfigurer implements WebMvcConfigurer {


    /**
     * 拦截所有三方支付接口请求
     */
    private static final String PAYMENT_API_PATH = "/pay-service/**";


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(validateAccessPaymentPermissionInterceptor())
                .addPathPatterns(PAYMENT_API_PATH).order(-8);
        registry.addInterceptor(getAppIdInterceptor())
                .addPathPatterns(PAYMENT_API_PATH);
    }

    @Bean
    public ValidateAccessPaymentPermissionInterceptor validateAccessPaymentPermissionInterceptor() {
        return new ValidateAccessPaymentPermissionInterceptor();
    }

    @Bean
    public GetAppIdInterceptor getAppIdInterceptor() {
        return new GetAppIdInterceptor();
    }
}
